<?php require_once('Connections/sepolwan_connect.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_sesi_member = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_sesi_member = $_SESSION['MM_Username'];
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_sesi_member = sprintf("SELECT * FROM memberdb WHERE email = %s", GetSQLValueString($colname_sesi_member, "text"));
$sesi_member = mysql_query($query_sesi_member, $sepolwan_connect) or die(mysql_error());
$row_sesi_member = mysql_fetch_assoc($sesi_member);
$totalRows_sesi_member = mysql_num_rows($sesi_member);

mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_chat = "SELECT DISTINCT * FROM chat WHERE ke = '".$row_sesi_member['nama_user']."' AND stat = 'ur' ORDER BY id DESC ";
$chat = mysql_query($query_chat, $sepolwan_connect) or die(mysql_error());
$row_chat = mysql_fetch_assoc($chat);
$totalRows_chat = mysql_num_rows($chat);

if ($totalRows_chat>0){
?><span style="background:#F00; padding:1px 4px; color:#FFF; border-radius:2px; -moz-border-radius:2px; -webkit-border-radius:2px;">
<font size="-2"><?php 
echo $totalRows_chat;
?></font></span>
<?php
}
mysql_free_result($sesi_member);

mysql_free_result($chat);

?>
